var url = decodeURI(location.href); // 获取URL
var followId = 0;
var type = "";
var index = 0;

var getSchoolDynamicsByIdUrl = baseUrl + "/common/schoolCommunicate/getSchoolDynamicsById";

function getQueryString(url) {
    if (url.split("?").length > 1) {
        var useUrl = url.split("?")[1];
        var params = new Array();
        var needParams = new Array();
        params = useUrl.split("&");
        for (var i = 0; i < params.length; i++) {
            var needParam = params[i].split("=")[1];
            needParams.push(needParam);
        }
        return needParams;
    } else {
        return null;
    }
}

$(function () {
    getNewsFresh();
    if (getQueryString(url) == null) {
        followId = JSON.parse(sessionStorage.getItem("followId"));
        type = JSON.parse(sessionStorage.getItem("type"));
        initOldXq();
    } else {
        followId = parseInt(getQueryString(url)[0]);
        initNewXq();
    }
})

function initNewXq() {
    getNews3();
}

function initOldXq() {
    if (type == "gg") {
        getNews3();
    } else if (type == "mxjl") {
        getSchoolDynamics();
    } else if (type == "jxal") {
        getResourceNews();
    } else if (type == "zxsczy") {
        getResourceupload();
    } else if (type == "gxjl_main_geXiaoDongTai") {
        // 各校动态
        getGxjlGeXiaoDongTai();
    } else if (type == "gxjl_main_zhuanTiYanJiu") {
        // 专题研究
        getGxjlGeXiaoDongTai();
    } else if (type == "fourBook_liLunQianYan") {
        // 理论前沿
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "fourBook_jiaoXueAnLi") {
        // 教学案例
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "mingShi_xueShuZhuZuo") {
        // 学术著作
        getMingShiXueShuZhuZuo();
    } else if (type == "mingShi_jiaoXueChengGuo") {
        // 教学成果
        getMingShiXueShuZhuZuo();
    } else if (type == "mingShi_xueShuLunWen") {
        // 学术论文
        getMingShiXueShuZhuZuo();
    } else if (type == "ggzyk_jiangDianWenXian") {
        // 经典文献
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "ggzyk_canYueZiLiao") {
        // 参阅资料
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "zjjs_shiJianAnLi") {
        // 实践案例
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "zjjs_hongChuanJingShen") {
        // 红船精神
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "zjjs_zheJiangXinWen") {
        // 浙江新闻
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "zjjs_liLunYanJiu") {
        // 理论研究
        getFourBookJiaoXueAnLiDetails();
    } else if (type == "shouYe_xinWenReDian") {
        // 获取首页新闻热点
        getShouYeXinWenReDian();
    } else if (type == "shouYe_mingXiaoDongTai") {
        // 获取首页名校动态
        getSchoolDynamics();
    } else if (type == "shouYe_heZuoYuanXiao") {
        // 获取首页合作院校
        getSchoolById();
    } else if (type == "ggzyk_zuiXin") {
        // 获取公共资源库最新
        getFourBookJiaoXueAnLiDetails();
    }
}

// 公告
function getNews3() {
    var data = {
        id: parseInt(followId)
    };
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getNewsById", getNews3_fun);
}
function getNews3_fun(res) {
    var newsLists3 = res.obj;
    console.log(res);
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(newsLists3.title);
        $(".RightBoxBottom").find(".toptitle").html(newsLists3.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + newsLists3.creatTime + '</p> ' +
            '<p>来源：</p> ' +
            '<p>' + newsLists3.whereFrom + '</p>');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + newsLists3.pic);
        $(".RightBoxBottom").find(".content").find("div").html(newsLists3.text);
    }
}

// 最新新闻
function getNewsFresh() {
    var data = {
        typeId: 2,
        page: index,
        size: 5
    };
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getNews", getNewsFresh_fun);
}
function getNewsFresh_fun(res) {
    var newsListsFresh = res.obj.content;
    // console.log(res);
    if (res.status == "SUCCESS") {
        $.each(newsListsFresh, function (i, newsListFresh) {
            $(".mainBox").find(".leftBox").find(".leftBoxBotom").find(".gonggao").find("ul").append('<li onclick=getOwnZuiXinXinWen("' + newsListFresh.id + '")><a href="javascript:;">' + newsListFresh.title + '</a></li>');
        })
    }
}

// 最新新闻
function getOwnZuiXinXinWen(id) {
    var data = {
        id: id
    }
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getNewsById", getOwnZuiXinXinWen_fun);
}
function getOwnZuiXinXinWen_fun(res) {
    // console.log(res);
    var schoolLists = res.obj;

    if (res.status == "SUCCESS") {
        $(".RightBoxBottom").find(".toptitle").html(schoolLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + schoolLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + schoolLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(schoolLists.text);
    }
}

// 名校交流
function getSchoolDynamics() {
    var data = {
        id: parseInt(followId)
    }
    AjaxSubmit("GET", data, basePath + "/common/firstPage/getSchoolDynamicsById", getSchoolDynamics_fun);
}
function getSchoolDynamics_fun(res) {
    // console.log(res);
    var schoolLists = res.obj;

    if (res.status == "SUCCESS") {
        $("#newsTitle").html(schoolLists.title);
        $(".RightBoxBottom").find(".toptitle").html(schoolLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + schoolLists.creatTime + '</p><p>新闻来源学校：' + schoolLists.schoolName + '</p>');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + schoolLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(schoolLists.content);
    }
}

// 教学案例
function getResourceNews() {
    var data = {
        id: parseInt(followId)
    };
    AjaxSubmit("GET", data, basePath + "/common/resource/getNewsById", getResourceNews_fun);
}
function getResourceNews_fun(res) {
    // console.log(res);
    var newsResourceLists = res.obj;
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".toptitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + newsResourceLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + newsResourceLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(newsResourceLists.text);
    }
}

// 最新上传资源
function getResourceupload() {
    var data = {
        id: parseInt(followId)
    };
    AjaxSubmit("GET", data, basePath + "/common/resource/getCommonResourceById", getResourceupload_fun);
}
function getResourceupload_fun(res) {
    type = "zxsczy";
    // console.log(res);
    var uploadResourceLists = res.obj;
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(uploadResourceLists.title);
        $(".RightBoxBottom").find(".toptitle").html(uploadResourceLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + uploadResourceLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + uploadResourceLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html('<a href=' + uploadResourceLists.fileUrl + ' target="_blank" style="color:blue">下载地址</a>');
    }
}

// 各校动态
function getGxjlGeXiaoDongTai() {
    var data = {
        id: followId
    };

    AjaxSubmit("GET", data, getSchoolDynamicsByIdUrl, getGxjlGeXiaoDongTaiRes);
}
function getGxjlGeXiaoDongTaiRes(res) {
    type = "gxjl_main_geXiaoDongTai";
    // console.log(res);
    var uploadResourceLists = res.obj;
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(uploadResourceLists.title);
        $(".RightBoxBottom").find(".toptitle").html(uploadResourceLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + uploadResourceLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + uploadResourceLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(uploadResourceLists.content);
    }
}

// 理论前沿
function getFourBookLiLunQianYan() {
    var data = {
        id: followId
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getTheoreticalFrontiers", getFourBookLiLunQianYanRes);
}
function getFourBookLiLunQianYanRes(res) {
    type = "gxjl_main_zhuanTiYanJiu";
    // console.log(res);
    var uploadResourceLists = res.obj.content[0];
    if (res.status == "SUCCESS") {
        $(".RightBoxBottom").find(".toptitle").html(uploadResourceLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + uploadResourceLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + uploadResourceLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(uploadResourceLists.text);
    }
}

// 教学案例
function getFourBookJiaoXueAnLiDetails() {
    var data = {
        id: followId
    };

    AjaxSubmit("GET", data, basePath + "/common/resource/getNewsById", getFourBookJiaoXueAnLiDetailsRes);
}
function getFourBookJiaoXueAnLiDetailsRes(res) {
    // console.log(res);
    var newsResourceLists = res.obj;
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".toptitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + newsResourceLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + newsResourceLists.pic);
        // $(".RightBoxBottom").find(".content").find("img").hide();
        $(".RightBoxBottom").find(".content").find("div").html(newsResourceLists.text);
    }
}

// 学术著作
function getMingShiXueShuZhuZuo() {
    var data = {
        id: followId
    };

    AjaxSubmit("GET", data, baseUrl + "/common/famousTeacher/getTeacherResource", getMingShiXueShuZhuZuoRes);
}
function getMingShiXueShuZhuZuoRes(res) {
    var newsResourceLists = res.obj.content[0];
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".toptitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + newsResourceLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + newsResourceLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(newsResourceLists.text);
    }
}

// 新闻热点
function getShouYeXinWenReDian() {
    var data = {
        id: followId
    };

    AjaxSubmit("GET", data, basePath + "/common/firstPage/searchCommonNews", getShouYeXinWenReDianRes);
}
function getShouYeXinWenReDianRes(res) {
    var newsResourceLists = res.obj.content[0];
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".toptitle").html(newsResourceLists.title);
        $(".RightBoxBottom").find(".small-list").html('<p>' + newsResourceLists.creatTime + '</p> ' +
            '<p>来源：</p> ' +
            '<p>' + newsResourceLists.whereFrom + '</p>');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + newsResourceLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(newsResourceLists.text);
    }
}

// 合作院校
function getSchoolById() {
    var data = {
        id: followId
    };

    AjaxSubmit("GET", data, basePath + "/common/firstPage/getSchoolById", getSchoolByIdRes);
}
function getSchoolByIdRes(res) {
    var newsResourceLists = res.obj;
    if (res.status == "SUCCESS") {
        $("#newsTitle").html(newsResourceLists.schoolName);
        $(".RightBoxBottom").find(".toptitle").html(newsResourceLists.schoolName);
        $(".RightBoxBottom").find(".small-list").html('<p>' + newsResourceLists.creatTime + '</p> ');
        $(".RightBoxBottom").find(".content").find("img").attr("src", basePath + newsResourceLists.pic);
        $(".RightBoxBottom").find(".content").find("div").html(newsResourceLists.brief);
    }
}